<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="/javascripts/admin.js"></script>
    <link rel="stylesheet" href="/stylesheets/admin.css">
</head>

<body>
    <div class="head">
        <div class="head-left">
            <p>后台管理</p>
            <a></a>
        </div>

        <div class="head-right">
            <a href="/admin/logout" class="users">退出登录</a>
            <a href="/admin/asort?aid=<%=user.aid%>&aname=<%=user.adname%>">密码修改</a>
        </div>
    </div>

    <!-- 左侧菜单栏 -->
    <div class="left-nav">
        <div class="matRun">
            <p>
                <%=user.adname%>
            </p>

        </div>

        <div class="run">
            <a>文章管理</a>
        </div>

    </div>

    <!-- 右侧显示栏 -->
    <div class="right-show">
        <table class="itemTop">
            <tr>
                <th>文章ID</th>
                <th>用户账号</th>
                <th>发布时间</th>
                <th>文章内容</th>
                <th>操作</th>
            </tr>
            <% textData.forEach(item=>{%>
                <tr>
                    <td>
                        <%=item.tid%>
                    </td>
                    <td>
                        <%=item.u_name%>
                    </td>
                    <td>
                        <%=item.release_time%>
                    </td>
                    <td>
                        <%=item.content_text%>
                    </td>
                    <td>

                        <button class="delBtn delet" data-tid="<%=item.tid%>">删除</button>

                    </td>
                </tr>
                <%})%>



        </table>

    </div>

    <script>
        document.querySelectorAll('.delet').forEach(a => {

            a.onclick = function () {
                if (!confirm('确认是否删除')) {
                    return
                }
                let u = this.getAttribute('data-tid')
                let xhr = new XMLHttpRequest();
                xhr.open('POST', '/admin/textd', true)
                xhr.responseType = 'json'
                xhr.setRequestHeader('Content-Type', 'Application/x-www-form-urlencoded')
                xhr.send(`tid=${u}`)

                xhr.onreadystatechange = function () {
                    if (xhr.readyState == 4 && xhr.status == 200) {

                        if (xhr.response.code == 200) {
                            alert("删除成功")
                            location.href = '/admin/showadmin';
                        } else {
                            alert("删除失败")

                        }
                    }
                }

            }


        })

    </script>
</body>

</html>